﻿using System;
using NineRays.WebControls;
using DBUtility;
using System.Data;


public partial class Topo_ImpMonitorIndex_SelTBS : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        AjaxPro.Utility.RegisterTypeForAjax(typeof(Topo_ImpMonitorIndex_SelTBS));
        if (!IsPostBack)
        {
            hidUserisn.Value = GetCookies.UserIsn;
            //CreateFlyTree();
        }
    }
   /* private void CreateFlyTree()
    {
        FlyTreeNode ftnArea = null;
        FlyTreeNode ftnRoom = null;
        string sqlStr = "select r.ROOMID as ROOMID,r.STATIONIP as ip,v.CHANNEL as CHANNEL,v.USERISN as USERISN,v.USERPWD as USERPWD,v.ID,v.NODEID";
        sqlStr += " from video_live v,room_list r ";
        sqlStr += " where v.ROOMID=r.ROOMID";
        DataTable dtVideo = new DataTable();
        dtVideo = DBUtility.OracleHelper.Query(sqlStr).Tables[0];

        sqlStr = "select userisn,ip,channel,username,pwd,roomid from recordvideo where userisn='" + hidUserisn.Value + "'";
        DataTable dtCheck = new DataTable();
        dtCheck = DBUtility.OracleHelper.Query(sqlStr).Tables[0];

        DataSet ds = new BLL.Common.ResourceStatus().GetEquipList("", "", "");
        this.ftvUnitTree.IsCheckbox = true;
        if (ds != null && ds.Tables[0].Rows.Count > 0)
        {
            DataTable dtArea = OracleHelper.SelectDistinct("equip", ds.Tables[0], "BELONGAREA");
            DataSetHelper dsh = new DataSetHelper();
            DataTable dtRoom = null;
            DataTable dtTmp = null;
            DataRow[] drArea = null;
            DataRow[] drRoom = null;
            DataRow[] drVideo = null;
            int areaLength = dtArea.Rows.Count;
            int roomLength = 0;
            int length = 0;
            for (int i = 0; i < areaLength; i++)
            {
                drArea = ds.Tables[0].Select("BELONGAREA='" + dtArea.Rows[i]["BELONGAREA"].ToString() + "'");
                dtTmp = dsh.RowToTable(drArea);
                dtRoom = OracleHelper.SelectDistinct("datatable", dtTmp, "BELONGROOM");
                roomLength = dtRoom.Rows.Count;
                ftnArea = CreateFlyTreeNode(drArea[0]["BELONGAREANAME"].ToString(), drArea[0]["BELONGAREA"].ToString(), true, "PARENT", "AREA", false, "", "", false, "");
                ftvUnitTree.Nodes.Add(ftnArea);
                for (int j = 0; j < roomLength; j++)
                {
                    drRoom = ds.Tables[0].Select("BELONGROOM='" + dtRoom.Rows[j]["BELONGROOM"].ToString() + "'");
                    length = drRoom.Length;
                    ftnRoom = CreateFlyTreeNode(drRoom[0]["ROOMNAME"].ToString(), drRoom[0]["BELONGROOM"].ToString(), true, "PARENT", "ROOM", false, "", "", false, "");
                    ftnArea.ChildNodes.Add(ftnRoom);
                    drVideo = dtVideo.Select("ROOMID='" + dtRoom.Rows[j]["BELONGROOM"].ToString() + "'");
                    for (int n = 0; n < drVideo.Length; n++)
                    {
                        //CreateFlyTreeNode(通道,ip,展开,用户名，密码)
                        bool ischeckedTemp = false;
                        for (int m = 0; m < dtCheck.Rows.Count; m++)
                        {
                            if (dtCheck.Rows[m]["roomid"].ToString() == drVideo[n]["roomid"].ToString() && dtCheck.Rows[m]["channel"].ToString() == drVideo[n]["CHANNEL"].ToString())
                            {
                                ischeckedTemp = true;
                            }
                        }
                        ftnRoom.ChildNodes.Add(CreateFlyTreeNode(drVideo[n]["CHANNEL"].ToString() + "号通道", drVideo[n]["IP"].ToString(), true, "SUBNODE", "VIDEO", true, drVideo[n]["USERISN"].ToString(), drVideo[n]["USERPWD"].ToString(), ischeckedTemp, drVideo[n]["roomid"].ToString()));
                    }
                }
            }
        }
    }*/
    /// 创建节点
    /// </summary>
    /// <param name="nodeName">节点名称</param>
    /// <param name="nodeID">节点ID</param>
    /// <param name="isExpand">是否展开节点</param>
    /// <param name="nodeType">节点类型(PARENT 根节点，SUBNODE 子节点)</param>
    /// <param name="isNavigate">是否导航</param>
    /// <returns></returns>
    public FlyTreeNode CreateFlyTreeNode(string nodeName, string nodeID, bool isExpand, string nodeType, string equiptype, bool isNavigate, string username, string pwd, bool isChecked, string roomid)
    {
        FlyTreeNode ftn = new FlyTreeNode();
        ftn.Value = nodeID;
        ftn.Text = nodeName;
        //ftn.IsCheckbox = true;
        ftn.Checked = isChecked;
        ftn.Expanded = isExpand;
        ftn.Attributes["flag"] = nodeType;
        ftn.Attributes["equiptype"] = equiptype;
        ftn.Attributes["username"] = username;
        ftn.Attributes["pwd"] = pwd;
        ftn.Attributes["roomid"] = roomid;

        switch (equiptype.ToUpper())
        {
            case "AREA":
                ftn.ImageUrl = "~/images/FlyTreeView/area.gif";
                break;
            case "ROOM":
                ftn.ImageUrl = "~/images/FlyTreeView/room.gif";
                break;
            case "10020001":

            case "VIDEO":
                ftn.ImageUrl = "~/images/FlyTreeView/TBS.gif";
                break;
            case "TBS":
                ftn.ImageUrl = "~/images/FlyTreeView/TBS.gif";
                break;
            case "LOOP4200":
            case "10020018":
                ftn.ImageUrl = "~/images/FlyTreeView/loop4200.gif";
                break;
            case "LOOP3440":
            case "10020017":
                ftn.ImageUrl = "~/images/FlyTreeView/loop4200.gif";
                break;
            case "FRAME":
            case "10020019":
                ftn.ImageUrl = "~/images/FlyTreeView/frame.gif";
                break;
            default:
                ftn.ImageUrl = "$kde_folder";
                break;
        }
        if (isNavigate)
        {
            ftn.NavigateTarget = "right";
            ftn.NavigateUrl = "EquipFaceplateRight.aspx?equipid=" + nodeID + "&equiptype=" + equiptype;
        }
        ftn.PopulateNodesOnDemand = true;
        return ftn;
    }

    private void LoopCheckFlyNodeTxt(FlyTreeNode NodeCheck, ref string strAllText, ref string strAllUnitid)
    {
        if (NodeCheck.Checked)
        {
            strAllText = strAllText + "," + NodeCheck.Text;
            strAllUnitid = strAllUnitid + "," + NodeCheck.Value;
        }
        if (NodeCheck.ChildNodes.Count > 0)
        {
            for (int i = 0; i < NodeCheck.ChildNodes.Count; i++)
            {
                LoopCheckFlyNodeTxt(NodeCheck.ChildNodes[i], ref  strAllText, ref strAllUnitid);
            }

        }
    }
    //当用户点击结点时，触发的事件
    protected void ftvUnitTree_PopulateNodes(object sender, NineRays.WebControls.FlyTreeNodeEventArgs e)
    {
        if (e.Node.ChildNodes.Count >= 0)
        {
            // AddChildNode(e.Node);
        }
    }
   /* [AjaxPro.AjaxMethod]
    public int excuteSql(string strSql)
    {
        int result = DBUtility.OracleHelper.ExecuteSql(strSql);
        return result;
    }*/

}
